<template>
	<view class="page">
		<view class="fill">
			<image src="/static/taobao/bg.png" mode="widthFix" class="bg"></image>
			<view class="search">
				<view class="searchInput" @click="$navTo('/pages/taobao/search')">
					<icon type="search" size="14" color="#ff374b"/>
					<text>复制商品链接搜优惠券</text>
				</view>
			</view>
		</view>
		<view class="big_cate">
			<view class="big_cate_item" @click="$navTo('/pages/taobao/typeShop?type=2')">
				<view class="logo">
					<image src="/static/taobao/dy.png" mode="widthFix"></image>
					<view class="b_tag">一分购</view>
				</view>
				<view>
					<view>抖音</view>
					<view class="b_tit">最高返50%</view>
				</view>
			</view>
			<view class="big_cate_item" @click="$navTo('/pages/taobao/typeShop?type=1')">
				<view class="logo">
					<image src="/static/taobao/pdd.png" mode="widthFix"></image>
					<view class="b_tag">省钱</view>
				</view>
				<view>
					<view>拼多多</view>
					<view class="b_tit">最高返50%</view>
				</view>
			</view>
		</view>
		<view class="cate">
			<view class="c_cate">
				<view class="c_type" :class="{'c_active':bigcate==2}" @click="changeBig(2)">抖音</view>
				<view class="line"></view>
				<view class="c_type" :class="{'c_active':bigcate==1}" @click="changeBig(1)">拼多多</view>
			</view>
			<scroll-view class="c_tag_list" scroll-x="true">
				<view class="c_tag"  @click="changebigCate(0)" :class="{'c_tag_active':bigcateActive==0}">推荐</view>
				<view class="c_tag" v-for="item in cateList" :class="{'c_tag_active':bigcateActive==item.menuid}" @click="changebigCate(item.menuid)">{{item.title}}</view>
			</scroll-view>
		</view>
		<view class="list">
			<view class="item" v-for="item in goodsList" @click="$navTo('/pages/taobao/detail?id='+item.product_id+'&type='+bigcate)">
				<view class="logo">
					<image :src="item.thumb" v-if="bigcate==1"></image>
					<image :src="item.cover" v-if="bigcate==2"></image>
				</view>
				<view class="content">
					<view class="title">
						<view class="tag tag_red" v-if="bigcate==1">拼多多</view>
						<view class="tag tag_black" v-if="bigcate==2">抖音</view>
						<text>{{item.title}}</text>
					</view>
					<view class="tags">
						<text class="tag" v-if="item.couponPrice>0">券 ￥{{item.couponPrice}}</text>
						<text class="tag" v-if="bigcate==1&&item.cos_fee>=0">返现 ￥{{item.cos_fee}}</text>
						<text class="tag" v-if="bigcate==2&&item.cosFee>=0">返现 ￥{{item.cosFee}}</text>
					</view>
					<view class="price">
						<text class="new">￥{{item.realprice}}</text>
						<text class="old">￥{{item.realprice}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="empty_loading">
			<image v-show="isloading" src="../../static/business/loading.gif" mode=""></image>
			<text v-show="isempty">没有更多了~</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isloading: false,
				isempty: false,
				bigcate: 2,//1拼多多 2抖音
				bigcateActive: 0,
				cateList: [],
				goodsList: [],
				page:0,
			};
		},
		onLoad(){
			this.getCate();
			if(uni.getStorageSync('token')){
				this.getClipContent();
			}
		},
		onShow(){
			if(!uni.getStorageSync('token')){
				uni.redirectTo({
					url: '/pages/public/login'
				})
			}
		},
		onReachBottom(){
			this.getList();
		},
		methods: {
			getClipContent(){
				uni.getClipboardData({
					success: function (res) {
						if(res.data!='getClipContent'&&res.data.length!=0){
							uni.showModal({
								title: '检测到剪贴板内容',
								content: res.data,
								confirmText: '立即搜索',
								success: function (ress) {
									if (ress.confirm) {
										uni.navigateTo({
											url: "/pages/taobao/search?keywords="+res.data
										})
									} else if (ress.cancel) {
										uni.hideToast()
									}
								}
							});
						}
					}
				});
			},
			changeBig(id){
				if(this.bigcate == id) return;
				this.bigcate = id;
				this.bigcateActive = 0;
				this.page = 0;
				this.cateList = [];
				this.goodsList = [];
				this.getCate();
			},
			changebigCate(id){
				if(this.bigcateActive == id) return;
				this.bigcateActive = id;
				this.page = 0;
				this.goodsList = [];
				this.getList();
			},
			
			getCate(){
				let php = '';
				if(this.bigcate==1){
					php = "duoduo";
				}else if (this.bigcate==2){
					php = "douyin";
				}
				this.$axios('index/goodscate', 'POST', php).then(res => {
					if(res.data.code==200){
						this.cateList = res.data.data;
						// this.bigcateActive = res.data.data[0].menuid;
						this.getList();
					}
				})
			},
			getList(){
				this.isempty = false;
				this.isloading = true;
				this.page++;
				let php = '';
				if(this.bigcate==1){
					php = "duoduo";
				}else if (this.bigcate==2){
					php = "douyin";
				}
				this.$axios('index/goodsList', 'POST', php,{
					page: this.page,
					cid: this.bigcateActive
				}).then(res => {
					this.isloading = false;
					if(res.data.code==200){
						this.goodsList = [...this.goodsList, ...res.data.data];
						this.isempty = res.data.data.length <= 0;
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		background: #f4f4f4;
	}
	.fill{
		position: relative;
		.bg{
			width: 100%;
		}
		.search{
			position: absolute;
			width: 100%;
			left: 0;
			top: calc(var(--status-bar-height));
			padding: 40rpx 20rpx;
			.searchInput{
				background: #fff;
				border-radius: 8rpx;
				color: #999;
				line-height: 2.8;
				padding-left: 24rpx;
				display: flex;
				align-items: center;
				width: 75%;
				text{
					margin-left: 12rpx;
				}
			}
		}
	}
	.big_cate{
		display: flex;
		justify-content: space-evenly;
		border-top-left-radius: 11rpx;
		border-top-right-radius: 11rpx;
		margin-top: -22rpx;
		background: #f4f4f4;
		position: relative;
		.big_cate_item{
			text-align: center;
			color: #333;
			display: flex;
			align-items: center;
			margin-top: 40rpx;
			.logo{
				width: 76rpx;
				// margin: 20px auto 8rpx;
				position: relative;
				margin-right: 20rpx;
				image{
					width: 100%;
				}
				.b_tag{
					position: absolute;
					right: -30rpx;
					top: -10rpx;
					color: #fff;
					font-size: 16rpx;
					border-radius: 10rpx;
					border: 1rpx solid #ff7d7e;
					background: #ff233d;
					padding: 2rpx 4rpx;
					border-bottom-left-radius: 0;
				}
			}
			.b_tit{
				font-size: 22rpx;
				color: #999;
			}
		}
	}
	.cate{
		padding: 0 20rpx;
		.c_cate{
			display: flex;
			justify-content: center;
			color: #969696;
			font-size: 36rpx;
			margin-top: 40rpx;
			.c_type{
				width: 108rpx;
			}
			.c_active{
				color: #333;
			}
			.line{
				width: 1rpx;
				height: 50rpx;
				background: #dcdcdc;
				margin: 0 50rpx;
			}
		}
		.c_tag_list{
			white-space: nowrap;
			padding: 30rpx 0 20rpx;
			.c_tag{
				display: inline-block;
				background: #fff;
				color:#979797;
				border-radius: 3rpx;
				padding: 5rpx 8rpx;
				margin-right: 18rpx;
				border: 1rpx solid #fff;
				font-size: 26rpx;
			}
			.c_tag_active{
				background: #ece5f1;
				color: #9c48d6;
				border: 1rpx solid $bg-color;
				font-size: 28rpx;
			}
		}
	}
	.list{
		padding: 0 20rpx 40rpx;
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		.item{
			width: 348rpx;
			background: #fff;
			margin-bottom: 15rpx;
			border-radius: 10rpx;
			overflow: hidden;
			.logo{
				width: 100%;
				image{
					width: 100%;
					height: 320rpx;
				}
			}
			.content{
				padding: 5rpx 12rpx 10rpx;
			}
			.title{
				.tag{
					border-radius: 5rpx;
					color: #fff;
					font-size: 16rpx;
					position: absolute;
					left: 0;
					top: 4rpx;
					width: 56rpx;
					height: 34rpx;
					text-align: center;
					line-height: 34rpx;
				}
				.tag_red{
					background: #f40009;
				}
				.tag_black{
					background: #141414;
				}
				font-weight: bold;
				line-height: 1.4;
				overflow: hidden;
				text-overflow: ellipsis;
				word-break: break-all;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				position: relative;
				text{
					word-wrap: break-all;
					white-space: pre-line;
					padding-left: 64rpx;
				}
			}
			.tags{
				margin-bottom: 15rpx;
				margin-top: 5rpx;
				.tag{
					color: #ff3333;
					border: 1rpx solid #ffdcdc;
					font-size: 20rpx;
					border-radius: 4rpx;
					margin-right: 8rpx;
					font-weight: bold;
					padding: 0 4rpx;
				}
			}
			.price{
				.new{
					font-weight: bold;
					font-size: 36rpx;
					margin-right: 16rpx;
				}
				.old{
					text-decoration: line-through;
					color: #bec4d4;
					font-size: 24rpx;
				}
			}
		}
	}
</style>
